<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				通知
			</block>
		</cu-custom>
		<a-fixed :height="40">
			<a-tabs :index="0" :row="tabs.length" type="border" :value="tabs" @click='inquire'></a-tabs>
		</a-fixed>
		<a-scroll :request="get" ref="aScroll" :parm="{pageSize:7}">
			<template #item="{row,index}">
				<uni-card-notice :thumbnail="msgImg" :is-shadow="true" mode="title" :title="row.title" :extra="row.extra" isShadow :note="row.date" @click="clickCard(row)">
					<text class="content-box-text">{{row.subTitle}}</text>
				</uni-card-notice>
			</template>
		</a-scroll>
	</view> 
</template>

<script>
	import {format} from '@/a/utils/api.js'
	export default {
		//上拉触底
		onReachBottom() {
			this.$refs.aScroll.lower();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.aScroll.get(true).then(res => {
				uni.stopPullDownRefresh();
			});
		},
		data() {
			return {
				msgImg:require('./msg.png'),
				tabs: [{
					msgTypeCode:'CLASS_NOTICE_APP',
					name: "班级通知"
				}, {
					msgTypeCode:'SCHOOL_NOTICE_APP',
					name: "学校通知"
				},
				/*{
					msgTypeCode:'MEETING__NOTICE_APP',
					name: "会议通知"
				},{
					msgTypeCode:'STU_OUT_INTO_HINT',
					name: "进出校提醒"
				}*/
				],
				
				//默认项
				tabsParm: {
					msgTypeCode:'CLASS_NOTICE_APP',
					name: "班级通知"
				}
			}
		},
		methods: {
			async get(parm) {
				return this.$http.get('/api/v1/bMessage/selectBMessagesByMsgTypeCode',{
					...parm,
					msgTypeCode:this.tabsParm.msgTypeCode
				}).then((result)=>{
					return {
						total:result.totalSize,
						data:result.results.map(x=>{
							return {
								...x,
								extra:'发布人:'+x.senderName,
								date:format(x.sendTime)
							}
						})
					}
				});
			},
			inquire(e) {
				this.tabsParm = e;
				this.$refs.aScroll.get(true);
			},
			clickCard(e) {
				uni.navigateTo({
					url: `./notice_details?id=${e.msgId}&senderName=${e.senderName}`
				});
			}
		}
	}
</script>

<style lang="scss">
	.content-box-text {
		font-size: 15px;
		font-weight: 500;
		line-height: 22px;
	}
</style>
